package com.langsin.Search;

/**
 * @Auther: MFM
 * @Date: 2021/8/18 - 08 - 18 - 16:05
 * @version: 1.0
 */

public class search {

    public static void main(String[] args) {
        int[] arr = {3, 11, 13, 92, 1314, 1234};
        int index = search(arr,1314);
        if (index == -1){
            System.out.println("数列中无此元素");
        }else {
            System.out.println("元素下标："+index);
        }
    }

    /**
     * 顺序查找，逐一查找
     *
     * @param arr   待查找数组
     * @param value 待查找元素
     * @return 待查找元素在数组中的下标
     */
    public static int search(int arr[], int value) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == value) {
                return i;
            }
        }
        return -1;
    }


}
